#include<stdio.h>
#include"process.h"
#include<time.h>
#include<stdlib.h>
#include<unistd.h>

typedef void (*flush_t)(double total, double current);

const int base = 20;
double total = 2048.0;
double once = 0.5;

void download(flush_t f)
{
    double current = 0.0;// 下载量
    while(current < total)
    {
        //模拟下载行为
        int r = rand() % base + 1; // [1,10]
        double speed = r * once;
        current += speed;
        if(current >= total) current = total;
        usleep(20000);
        
        // 更新除了本次的下载量
        // 根据真实的应用场景，进行动态刷新
        f(total,current);

       // printf("%.1lf/\%.1lf\r",current,total);
       // fflush(stdout);
    }
    printf("\n");

}


int main()
{
    srand(time(NULL));
    download(FlushProcess);
    return 0;
}
